%% 290 Class Notes January 20

% Note: Anthing after the '%' symbol is a comment and is ignored by MATALB.

% We can use MATLAB as a calculator
% Typing the following into the command window gives the expected results

2+2

2+3*2

% Note that normal rules of mathematical orders of operatation are obeyed. 

% Helpful Trick:  Select text in the editor and hit F9. That text is run in
% the command window. 

% By default, the results are assigned to variable 'ans'.  Assign them to
% a particular variable:

X=2+2
Y=2+3*2

% We can do math with variables:
X*Y
Z=X*Y

%Variable names must start with a letter and cannont have special
%characters. 

LongVariableName777 = X*Y +5


% The ';' suppresses the output to the command window.  The comment lets us keep track of the
% units. 
c=3*10^8;   % speed of light (m/s)

% We often want to work with arrays or matracies

%Create a 3x2 matrix of zeros:
A=zeros(3,2)

% 'zeros' is a function.  We'll get into function in more detail in the next lectures. 
% Learn about 'zeros' using the 'help' and 'doc'
help zeros
doc zeros

% Note the first index is the length of the column.  The second is the
% length of a row.  

%Get the top right element
A(1,2)

%Change the top right element
A(1,2)=3

% Get the top right element- note it is changed. 
A(1,2)

%MATLAB default type of data is the 'double'.  It uses 8 bytes (64 bits) to
%encode a floating point number.  If you are interested, learn more about
%floating point numbers here: https://en.wikipedia.org/wiki/Floating_point

%If you run the following it will open a web browser:
web('https://en.wikipedia.org/wiki/Floating_point')

%we can convert between some data types
B=single(A)

% 'single' is a function that converts the input in a single floating point
% data type.  Note the other data types mentioned at the end of the help:
help single

single('asdsf')

% One of the first things to do in a new language is print the 'Hello
% World message.  In MATLAB, we use the 'fprintf' to print to the command
% window. 

fprintf('Hello World\n')

%Try with double quotes "" instead of single ''.  See what happens. 

% you can run everyhing in this file at once by running the script:
% type 'Jan_20' in the command window.  What will happen if I uncomment the
% next line? (Hint: cntr-c interrupts a running script or function)
% Jan_20















